package com.joelemon.mockinfluxdbdata.core.log;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.joelemon.mockinfluxdbdata.mock.VisableInfo;
import com.joelemon.mockinfluxdbdata.utils.JsonUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * @Description: mock任务
 * @Author: HJY
 * @Date: 2023/11/20
 */
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@TableName("mock_task_log")
public class MockTaskLog {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    @TableField("`task_id`")
    private Long taskId;
    @TableField("`running_info`")
    private String runningInfo;
    @TableField("`create_time`")
    private DateTime createTime;
    @TableField("`error_mes`")
    private String errorMes;

    public static MockTaskLog createLog(VisableInfo visableInfo, String errorMes) {
        MockTaskLog mockTaskLog = new MockTaskLog();
        mockTaskLog.setTaskId(visableInfo.getTaskId());
        mockTaskLog.setRunningInfo(JsonUtil.convertJsonString(visableInfo));
        mockTaskLog.setCreateTime(new DateTime());
        mockTaskLog.setErrorMes(errorMes);
        return mockTaskLog;
    }
}
